package com.ja.openchat.http;

import android.app.Application;

import com.ja.openchat.api.ApiUtils;
import com.lzy.okgo.callback.AbsCallback;

import java.io.File;
import java.util.List;


public class HttpUtil {
    /**
     * 初始化
     */
    public static void init(Application s, String host) {
        HttpClient.getInstance().init(s, host);
        HttpVueClient.getInstance().init(s, ApiUtils.URL_VUE);
        HttpExClient.getInstance().init(s, ApiUtils.URL_E);
    }
    public static void initToken(String token){
        HttpClient.getInstance().setToken(token);
    }
    /**
     * 取消网络请求
     */
    public static void cancel(String tag) {
        HttpClient.getInstance().cancel(tag);
    }


    /**
     * 首页中间菜单样式信息
     * @param tag
     * @param callback
     */
    public static void getMiddleMenuInfo(String tag, AbsCallback callback) {
        HttpClient.getInstance().get(ApiUtils.GET_MIDDLE_MENU_INFO, tag)
                .execute(callback);
    }


    /**
     * 上传文件(支持多文件)
     *
     * @param fileList
     * @param callback
     */
    public static void postFile(List<File> fileList, String tag, HttpCallback callback) {
        HttpClient.getInstance().post("storage/upload", tag)
                .addFileParams("file", fileList)
                .execute(callback);

    }


    public static void getMyPages4(String uid, int p, String tag, HttpCallback callback) {
        HttpClient.getInstance().getPage("publishs/getPublishsByUserId", tag, p)
                .params("userId", uid)
                .params("noSeeStatus", 4)
                .execute(callback);
    }

    /**
     * 动态详情
     *
     * @param id
     * @param callback
     */
    public static void getPublishsById(String uid, String id, String tag, HttpCallback callback) {
        HttpClient.getInstance().get("publishs/getPublishsById", tag)
                .params("checkUserId", uid)
                .params("id", id)
                .execute(callback);
    }

    /**
     * 新增动态评论
     *
     * @param publishId
     * @param comment
     * @param commentPic
     * @param callback
     */
    public static void addPublishComments(String uid, String uName, String publishId, String comment, String commentPic, HttpCallback callback) {
        HttpClient.getInstance().post("publishComments/addPublishComments", "DYNAMIC")
                .params("publishId", publishId)
                .params("comment", comment)
                .params("userId", uid)
                .params("userName", uName)
                .params("commentPic", commentPic)
                .execute(callback);
    }


}


